package ar.com.gals.repository;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Restrictions;

import ar.com.gals.domain.Rol;

public class RolRepository extends AbstractRepository<Rol> {

	public RolRepository(Session session) {
		super(session, Rol.class);
	}

	@SuppressWarnings("unchecked")
	public Rol getByName(String rolName) {
		Criteria criteria = this.session.createCriteria(domain)
				.add(Restrictions.ilike("nombre", rolName))
				.add(Restrictions.isNull("fechaDelete"))
				.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
		List<Rol> list = (List<Rol>) criteria.list();
		if(list.isEmpty()) return null;
		return (Rol) list.get(0);
	}
}
